#pragma once
#include <queue>
#include <mutex>
#include <condition_variable>
#include "EventTypes.h"


class EventQueue {
public:
    // 添加事件到队列
    void push(Event&& event) {
        std::lock_guard<std::mutex> lock(m_mutex);
        m_queue.push(std::move(event));
        m_condition.notify_one();
    }
    
    // 从队列中取出事件
    bool pop(Event& event) {
        std::unique_lock<std::mutex> lock(m_mutex);
        m_condition.wait(lock, [this] { return !m_queue.empty(); });
        
        if (!m_queue.empty()) {
            event = std::move(m_queue.front());
            m_queue.pop();
            return true;
        }
        return false;
    }
    
    // 检查队列是否为空
    bool empty() const {
        std::lock_guard<std::mutex> lock(m_mutex);
        return m_queue.empty();
    }
    
    // 获取队列大小
    size_t size() const {
        std::lock_guard<std::mutex> lock(m_mutex);
        return m_queue.size();
    }
    
private:
    mutable std::mutex m_mutex;
    std::condition_variable m_condition;
    std::queue<Event> m_queue;
};
